home *** CD-ROM | disk | FTP | other *** search
/ Aminet 35 / Aminet 35 (2000)(Schatztruhe)[!][Feb 2000].iso / Aminet / dev / src / td01_src.lha / td_r0.1 / developing / Test / TesttdLib.c < prev    next >
Encoding:
C/C++ Source or Header  |  1999-06-06  |  7.7 KB  |  227 lines

  1. #include <exec/types.h>
  2. #include <exec/memory.h>
  3.  
  4. #include <pragma/exec_lib.h>
  5.  
  6. #include <stdio.h>
  7. #include <stdlib.h>
  8.  
  9.  
  10. #include "td.h"
  11.  
  12. void main(long argc, char **argv)
  13. {
  14.    ULONG space,i,j,n,k,nof,value,txb;
  15.    TDfloat ff,fa3[3];
  16.    TDdouble da3[3],dx,dy,dz;
  17.    TDenum type;
  18.    STRPTR name;
  19.    TDvectord dv,dv1,dv2,dv3,dv4;
  20.    TDvectorf fv;
  21.  
  22.    if((space=tdSpaceNew())!=0) {
  23.  
  24.      tdNameGet(space,TD_SPACE,0,&name);
  25.      printf("Name : (%s)\n",name);
  26.  
  27.      tdNameSet(space,TD_SPACE,0,"Esel");
  28.  
  29.      tdNameGet(space,TD_SPACE,0,&name);
  30.      printf("Name : (%s)\n",name);
  31.  
  32.      tdAdd(space,TD_TEXTURE);
  33.      i=tdNofGet(space,TD_MATERIAL);
  34.      tdNameSet(space,TD_MATERIAL,i,"mauer");
  35.  
  36.      tdAdd(space,TD_SURFACE);
  37.      i=tdNofGet(space,TD_MATERIAL);
  38.      fa3[0]=1.0,fa3[1]=0.0,fa3[2]=0.0;
  39.      tdMaterialSetfa(space,TD_DIFFUSE,i,fa3);
  40.      tdNameSet(space,TD_MATERIAL,i,"rot");
  41.      tdMaterialSetf(space,TD_SHININESS,i,0.8);
  42.      tdMaterialSetf(space,TD_TRANSPARENCY,i,0.2);
  43.  
  44.      tdAdd(space,TD_SURFACE);
  45.      i=tdNofGet(space,TD_MATERIAL);
  46.      fa3[0]=0.0,fa3[1]=0.0,fa3[2]=1.0;
  47.      tdMaterialSetfa(space,TD_DIFFUSE,i,fa3);
  48.      tdNameSet(space,TD_MATERIAL,i,"blau");
  49.      tdMaterialSetf(space,TD_SHININESS,i,0.4);
  50.      tdMaterialSetf(space,TD_TRANSPARENCY,i,0.7);
  51.  
  52.      tdAdd(space,TD_SURFACE);
  53.      i=tdNofGet(space,TD_MATERIAL);
  54.      fa3[0]=0.0,fa3[1]=1.0,fa3[2]=0.0;
  55.      tdMaterialSetfa(space,TD_DIFFUSE,i,fa3);
  56.      tdNameSet(space,TD_MATERIAL,i,"grĂ¼n");
  57.      tdMaterialSetf(space,TD_SHININESS,i,0.4);
  58.      tdMaterialSetf(space,TD_TRANSPARENCY,i,0.7);
  59.  
  60.      tdAdd(space,TD_TEXBINDING);
  61.      txb=tdNofGet(space,TD_OBJECT);
  62.      tdNameSet(space,TD_OBJECT,txb,"Mauerposition");
  63.  
  64.      printf("Number of materials : %ld\n",nof=tdNofGet(space,TD_MATERIAL));
  65.  
  66.      for(i=1;i<=nof;i++) {
  67.        name[0]='\0'; fa3[0]=0; fa3[1]=0; fa3[2]=0; ff=0.0;
  68.  
  69.        tdNameGet(space,TD_MATERIAL,i,&name);
  70.        tdTypeGet(space,TD_MATERIAL,i,&type);
  71.        switch(type) {
  72.          case TD_SURFACE :
  73.            printf("  surface at index : %ld\n",i);
  74.            printf("  name  : (%s)\n",name);
  75.            tdMaterialGetfa(space,TD_AMBIENT,i,fa3);
  76.            printf("  ambient color %6.3g %6.3g %6.3g\n",fa3[0],fa3[1],fa3[2]);
  77.            tdMaterialGetfa(space,TD_DIFFUSE,i,fa3);
  78.            printf("  diffuse color %6.3g %6.3g %6.3g\n",fa3[0],fa3[1],fa3[2]);
  79.            tdMaterialGetf(space,TD_SHININESS,i,&ff);
  80.            printf("  shininess    %6.3g\n",ff);
  81.            tdMaterialGetf(space,TD_TRANSPARENCY,i,&ff);
  82.            printf("  transparency %6.3g\n",ff);
  83.  
  84.            break;
  85.          case TD_TEXTURE :
  86.            printf("  texture at index : %ld\n",i);
  87.            printf("  name  : (%s)\n",name);
  88.        }
  89.      }
  90.  
  91.      tdAdd(space,TD_CUBE);
  92.      i=tdNofGet(space,TD_OBJECT);
  93.      fa3[0]=2.0;fa3[1]=4.0;fa3[2]=3.0;
  94.      tdObjectSetfa(space,TD_CUBE,i,fa3);
  95.      fa3[0]=1.1;fa3[1]=1.2;fa3[2]=1.3;
  96.      tdObjectSetfa(space,TD_ORIGIN,i,fa3);
  97.      fa3[0]=2.1;fa3[1]=2.2;fa3[2]=2.3;
  98.      tdObjectSetfa(space,TD_SCALE,i,fa3);
  99.      fa3[0]=3.1;fa3[1]=3.2;fa3[2]=3.3;
  100.      tdObjectSetfa(space,TD_ROTATION,i,fa3);
  101.  
  102.      tdAdd(space,TD_POLYMESH);
  103.      i=tdNofGet(space,TD_OBJECT);
  104.      tdNameSet(space,TD_OBJECT,i,"Testobjekt");
  105.  
  106.      tdCurrent(space,TD_OBJECT,i);
  107.        tdCurrent(space,TD_MATERIAL,tdNofGet(space,TD_MATERIAL));
  108.          tdBegin(space,TD_MATGROUP);
  109.            tdBegin(space,TD_POLYGON);
  110.              tdVertexAdd3f(space,10.1,10.0,9.9);
  111.              tdVertexAdd3f(space,9.8,9.7,9.6);
  112.              tdVertexAdd3f(space,9.5,9.4,9.3);
  113.              tdVertexAdd3f(space,9.2,9.1,9.0);
  114.            tdBegin(space,TD_POLYGON);
  115.              da3[0]=1.1;da3[1]=1.2;da3[2]=1.3;
  116.              tdVertexAdd3da(space,da3);
  117.              da3[0]=1.4;da3[1]=1.5;da3[2]=1.6;
  118.              tdVertexAdd3da(space,da3);
  119.              da3[0]=1.7;da3[1]=1.8;da3[2]=1.9;
  120.              tdVertexAdd3da(space,da3);
  121.            tdEnd(space,TD_POLYGON);
  122.        tdCurrent(space,TD_MATERIAL,1);
  123.          tdBegin(space,TD_MATGROUP);  
  124.            dv1.x=30.1,dv1.y=30.1,dv1.z=30.2;
  125.            dv2.x=30.3,dv2.y=30.4,dv2.z=30.5;
  126.            dv3.x=30.6,dv3.y=30.7,dv3.z=30.8;
  127.            dv4.x=30.9,dv4.y=30.0,dv4.z=30.01;
  128.            tdQuadAdd4dv(space,&dv1,&dv2,&dv3,&dv4);
  129.            tdChildSetl(space,TD_MATERIAL,2);
  130.            tdChildSetl(space,TD_TEXBINDING,txb);
  131.          tdEnd(space,TD_MATGROUP);
  132.        tdEnd(space,TD_MATERIAL);
  133.      tdEnd(space,TD_OBJECT);
  134.  
  135.      printf("Number of objects : %ld\n",nof=tdNofGet(space,TD_OBJECT));
  136.  
  137.      for(i=1;i<=nof;i++) {
  138.        name[0]='\0'; da3[0]=0; da3[1]=0; da3[2]=0;type=0;
  139.  
  140.        tdNameGet(space,TD_OBJECT,i,&name);
  141.        printf("->index : %ld\n",i);
  142.        printf("  name  : (%s)\n",name);
  143.        tdObjectGetda(space,TD_ORIGIN,i,da3);
  144.        printf("Object its origin   %6.3g %6.3g %6.3g\n",da3[0],da3[1],da3[2]);
  145.        tdObjectGetda(space,TD_SCALE,i,da3);
  146.        printf("Object its scale    %6.3g %6.3g %6.3g\n",da3[0],da3[1],da3[2]);
  147.        tdObjectGetda(space,TD_ROTATION,i,da3);
  148.        printf("Object its rotation %6.3g %6.3g %6.3g\n",da3[0],da3[1],da3[2]);
  149.        tdTypeGet(space,TD_OBJECT,i,&type);
  150.        switch(type) {
  151.          case TD_TEXBINDING :
  152.            printf("Texture binding\n");
  153.             break;
  154.          case TD_CUBE :
  155.            tdObjectGetfa(space,TD_CUBE,i,fa3);
  156.            printf("Cube\n xyz %6.3g %6.3g %6.3g\n",fa3[0],fa3[1],fa3[2]);
  157.             break;
  158.          case TD_POLYMESH :
  159.            tdCurrent(space,TD_OBJECT,i);
  160.            printf("polygons : %ld\n",tdNofGet(space,TD_POLYGON));
  161.            printf("vertices : %ld\n",tdNofGet(space,TD_VERTEX));
  162.  
  163.            for(k=1;k<=tdNofGet(space,TD_MATGROUP);k++) {
  164.              tdCurrent(space,TD_MATGROUP,k);
  165.  
  166.              printf(" matgroup %ld\n",k);
  167.              tdChildGetl(space,TD_MATERIAL,&value);
  168.              printf("  materialindex : %ld\n",value);
  169.              tdChildGetl(space,TD_TEXBINDING,&value);
  170.              printf("  texbindex     : %ld\n",value);
  171.              printf("  polygons : %ld\n",tdNofGet(space,TD_POLYGON));
  172.              printf("  vertices : %ld\n",tdNofGet(space,TD_VERTEX));
  173.  
  174.              for(j=1;j<=tdNofGet(space,TD_POLYGON);j++) {
  175.                printf(" polygon %ld\n",j);
  176.                tdCurrent(space,TD_POLYGON,j);
  177.                for(n=1;n<=tdNofGet(space,TD_VERTEX);n++) {
  178.                  printf("  vertices : %ld\n",tdNofGet(space,TD_VERTEX));
  179.                  dv.x=0.0;dv.y=0.0;dv.z=0.0;
  180.                  dx=0.0;dy=0.0;dz=0.0;
  181.  
  182.                  tdVertexGetdv(space,n,&dv);
  183.                  tdVertexGet3d(space,n,&dx,&dy,&dz);
  184.                  printf("  ->index : %ld\n",n);
  185.                  printf("         VGet Get\n");
  186.                  printf("    x  : %0.4g  %0.4g\n",dv.x,dx);
  187.                  printf("    y  : %0.4g  %0.4g\n",dv.y,dy);
  188.                  printf("    z  : %0.4g  %0.4g\n",dv.z,dz);
  189.                }
  190.                tdEnd(space,TD_POLYGON);
  191.              }
  192.              tdEnd(space,TD_MATGROUP);
  193.            }
  194.            
  195.            printf("Number of polygons in the object : %ld\n",tdNofGet(space,TD_POLYGON));
  196.  
  197.            tdVertexAdd3f(space,1.1,1.2,1.3);
  198.            dv.x=2.1;dv.y=2.2;dv.z=2.3;
  199.            tdVertexAdddv(space,&dv);
  200.  
  201.            printf("Number of vertices  : %ld\n",tdNofGet(space,TD_VERTEX));
  202.            for(i=1;i<=tdNofGet(space,TD_VERTEX);i++) {
  203.       
  204.              fv.x=0.0;fv.y=0.0;fv.z=0.0;
  205.              dx=0.0;dy=0.0;dz=0.0;
  206.  
  207.              tdVertexGetfv(space,i,&fv);
  208.              tdVertexGet3fa(space,i,fa3);
  209.              printf("->index : %ld\n",i);
  210.              printf("       VGet Get\n");
  211.              printf("  x  : %0.4g  %0.4g\n",fv.x,fa3[0]);
  212.              printf("  y  : %0.4g  %0.4g\n",fv.y,fa3[1]);
  213.              printf("  z  : %0.4g  %0.4g\n",fv.z,fa3[2]);
  214.            }
  215.  
  216.            tdEnd(space,TD_OBJECT);
  217.  
  218.          break;
  219.        }
  220.      }
  221.  
  222.      tdSpaceDelete(space);
  223.    } else {
  224.      printf("Could not create the space.\n");
  225.    }
  226. }
  227.